home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Samples / SampleCode / BoxPaint+ - non stereo / sources / BoxPaint_main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-14  |  5.6 KB  |  248 lines  |  [TEXT/CWIE]

  1. /*  main.c                                                                            
  2.                                                                                     
  3.   This is BoxPaint, a sample app designed to show how getting UV data from
  4.   a pick object can be used to draw on a texture. This app does not have        
  5.   graceful error handling - it's purpose is to demonstrate UV picking.                                                                        
  6.                                                                                     
  7.   Michael Bishop - August 21 1996                                                    
  8.   Nick Thompson
  9.   Robert Dierkes                                                                                
  10.   (c)1994-96 Apple Computer Inc., All Rights Reserved                                
  11.  
  12. */
  13.  
  14. /*  system headers */
  15. #include    <Devices.h>
  16. #include    <Dialogs.h>
  17. #include    <DiskInit.h>
  18. #include    <Events.h>
  19. #include    <Fonts.h>
  20. #include    <Menus.h>
  21. #include    <PictUtils.h>
  22. #include    <QDOffScreen.h>
  23. #include    <QuickDraw.h>
  24. #include    <SegLoad.h>
  25. #include    <StandardFile.h>
  26. #include    <TextEdit.h>
  27.  
  28. #include    "BoxPaint_main.h"
  29. #include    "BoxPaint_utility.h"
  30. #include    "BoxPaint_document.h"
  31. #include    "BoxPaint_window.h"
  32. #include    "BoxPaint_menu.h"
  33. #include    "BoxPaint_event.h"
  34.  
  35. #include    "QD3D.h"
  36.  
  37. /* -------------------------------------------------------------------------------------------
  38. ** function prototypes
  39. */
  40.  
  41. static void InitToolbox( void ) ;
  42. static void Main_EventLoop( void ) ;
  43. static void    Main_Init( short mBarResourceID, short numMoremasters);
  44. static void    Main_Destroy( void );
  45.  
  46.  
  47. /* -------------------------------------------------------------------------------------------
  48. ** Global Variables
  49. */
  50.  
  51. Boolean         gQuitFlag         = false ;
  52. Boolean            gForeground        = true ;
  53. short            gTicks            = 1 ;
  54.  
  55. /* -------------------------------------------------------------------------------------------
  56. **  main() 
  57. **  entry point for the application, initialize the toolbox, initialize QuickDraw 3D 
  58. **  and enter the main event loop.  On exit from the main event loop, we want to call 
  59. **  the QuickDraw 3D exit function to clean up QuickDraw 3d. 
  60. */
  61.  
  62. void main( void ) 
  63. {
  64.     Main_Init( kMBARResID, 5 ) ;            /* initialise the toolbox, load our menubar */
  65.  
  66.     Document_New();
  67.     
  68.     Main_EventLoop() ;
  69.     
  70.     /* tear down any we allocated */
  71.     Main_Destroy() ;    
  72.     
  73.     /* and bail */
  74.     ExitToShell() ;
  75. }
  76.  
  77. /*    -------------------------------------------------------------------------------------------
  78. **    Main_Init
  79. **    Initialize our environment, pass in the mbar resource ID, and also the number of calls 
  80. **    to make to moremasters
  81. */
  82.  
  83. void Main_Init( short mBarResourceID, short numMoremasters)
  84. {
  85.     Handle        menuBar = nil;
  86.     short        loopCounter ;
  87.     TQ3Status    myStatus ;
  88.     
  89.     MaxApplZone() ;        /* max out the apps heap */
  90.     
  91.     for( loopCounter = 0; loopCounter < numMoremasters ; loopCounter++ )
  92.         MoreMasters() ;
  93.         
  94.     InitToolbox() ;
  95.     
  96.     /* initialize anything else we need to */
  97.     
  98.     /* init QuickDraw 3D, open a connection to the QuickDraw 3D library */
  99.     myStatus = Q3Initialize();
  100.  
  101.     if ( myStatus == kQ3Failure )
  102.         DebugStr("\pQ3Initialize returned failure.");            
  103.     
  104.     
  105.     /*  initialize application globals */
  106.     
  107.     gQuitFlag = false;
  108.     gForeground = true;
  109.     gTicks        = 1;
  110.     /* load the application menu bar */
  111.     
  112.     menuBar = GetNewMBar( mBarResourceID );    /* Read menus into menu bar, MBAR res id is 128 */
  113.     
  114.     if ( menuBar == nil )
  115.          ExitToShell();                        /* if we dont have it then quit - your app */
  116.                                              /* needs a dialog here */
  117.  
  118.     SetMenuBar(menuBar);                    /* Install menus */
  119.     DisposHandle(menuBar);
  120.     
  121.     AddResMenu(GetMHandle(mApple), 'DRVR');    /* Add DA names to Apple menu, ID 128 */
  122.  
  123.     Menu_Adjust() ;
  124.     DrawMenuBar();
  125. }
  126.  
  127.  
  128.  
  129. void Main_Destroy( void )
  130. {
  131.     Window_DestroyAll();
  132.         
  133.     Q3Exit() ;
  134.  
  135. }
  136.  
  137. /*    --------------------------------------------------------------------
  138. **    InitToolbox
  139. **    Initialize the toolbox managers
  140. */
  141. void InitToolbox( void )
  142. {
  143.     
  144.     InitGraf( &qd.thePort );
  145.     InitFonts();
  146.     InitWindows();
  147.     InitCursor();
  148.     InitDialogs( nil ) ;
  149.  
  150.     FlushEvents( everyEvent, 0 ) ;
  151. }
  152.  
  153.  
  154.  
  155. /*    --------------------------------------------------------------------
  156. **    Main_EventLoop
  157. **    The heart of the app. Handles all interaction
  158. */
  159. void Main_EventLoop()
  160. {
  161.     EventRecord     theEvent;
  162.     WindowPtr       theWindow;
  163.     short           thePart;
  164.     Rect            screenRect;
  165.     Point            aPoint = {100, 100};
  166.     Boolean            eventPresent = false;
  167.  
  168.     while( !gQuitFlag )
  169.     {
  170.         eventPresent = WaitNextEvent( everyEvent, &theEvent, gTicks, nil );
  171.         
  172.         if (eventPresent == true)
  173.         {
  174.             switch (theEvent.what) {
  175.                 case mouseDown:
  176.                 
  177.                     thePart = FindWindow( theEvent.where, &theWindow ) ;
  178.                     
  179.                     switch( thePart ) {
  180.                         case inMenuBar: 
  181.                             Menu_Adjust() ;
  182.                             Menu_HandleCommand(MenuSelect(theEvent.where));
  183.                             break;
  184.                         
  185.                         case inDrag:
  186.                             screenRect = (**GetGrayRgn()).rgnBBox;
  187.                             DragWindow( theWindow, theEvent.where, &screenRect );
  188.                             break ;
  189.                     
  190.                         case inContent:
  191.                             if (theWindow != FrontWindow())
  192.                                 SelectWindow( theWindow );
  193.                             Window_DoContent(theWindow, &theEvent);
  194.                             break ;
  195.                     
  196.                         case inGoAway:
  197.                             if (TrackGoAway( theWindow, theEvent.where )) {
  198.                                 Document_Dispose( Window_GetDocument(theWindow) ) ;
  199.                             }
  200.                             break ;
  201.                             
  202.                         default:
  203.                             break ;
  204.                     }
  205.                     break ;
  206.                             
  207.                         
  208.                 case updateEvt:
  209.                 
  210.                     theWindow = (WindowPtr)theEvent.message;
  211.                     Window_Update( theWindow ) ;
  212.                     break ;
  213.                     
  214.                 case keyDown:
  215.                 case autoKey:
  216.                     Event_HandleKeyPress(&theEvent);
  217.                     break;
  218.                     
  219.                 case diskEvt:
  220.                     if ( Utility_HiWrd(theEvent.message) != noErr ) 
  221.                         (void) DIBadMount(aPoint, theEvent.message);
  222.                     break;
  223.                     
  224.                 case osEvt:
  225.                     Event_DoOSEvent(theEvent);
  226.                     break;
  227.  
  228.                 case activateEvt:
  229.                     break;
  230.             }
  231.         }
  232.         else {
  233. /*                Event_DoNull();    */    /* Handle the Null Event */
  234.  
  235.         }
  236.     }
  237. }
  238.  
  239. /*    --------------------------------------------------------------------
  240. **    Main_DoAbout
  241. **    Display the About Box
  242. */
  243. void Main_DoAbout( void )
  244. {
  245.     short                itemHit ;
  246.     
  247.     itemHit = Alert ( 128, nil ) ;
  248. }